package com.shushan.shushanbao;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;

import com.huawei.android.hms.agent.HMSAgent;
import com.huawei.android.hms.agent.common.handler.CheckUpdateHandler;
import com.huawei.android.hms.agent.common.handler.ConnectHandler;
import com.shushan.base.Constants;
import com.shushan.home.TabHomeActivity;
import com.shushan.login.LoginOrRegisterActivity;
import com.shushan.setting.ParentPswSetActivity;
import com.shushan.util.SharedPreferencesUtils;
import com.shushan.pages.VideoPageActivity;

/**
 * @ClassName: HomeSwitchActivity
 * @Desciption: 首页进入的判断
 * @author: yichaohua
 * @date: 2018-04-16
 */
public class HomeSwitchActivity extends Activity {

    private static final String TAG = "HomeSwitchActivity";


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if(getPackageName().equals(Constants.HUAWEI_PACKAGE_NAME)){
            HMSAgent.connect(this, new ConnectHandler() {
                @Override
                public void onConnect(int rst) {
                    Log.i(TAG,"HMS connect end:" + rst);

                    HMSAgent.checkUpdate(HomeSwitchActivity.this, new CheckUpdateHandler() {
                        @Override
                        public void onResult(int rst) {
                            Log.i(TAG,"rst=" + rst);
                        }
                    });
                }
            });
        }

        boolean appNotFirst = SharedPreferencesUtils.getBooleanDate(Constants.APP_NOT_FIRST_SHAREPREFERS_KEY);
        Log.i(TAG,"appNotFirst=" + appNotFirst);

        if(appNotFirst){
            boolean isLogin = SharedPreferencesUtils.getBooleanDate(Constants.IS_LOGIN_SHAREPREFERS_KEY);
            if(isLogin){
                String parentPasswd = SharedPreferencesUtils.getStringDate(Constants.PARENT_PASSWD_SHAREPREFERS_KEY,"");
                if(TextUtils.isEmpty(parentPasswd)){
                    startActivity(new Intent(this,ParentPswSetActivity.class));
                }else {
                    startActivity(new Intent(this,TabHomeActivity.class));
                }

            }else {
                Intent intent = new Intent(this,LoginOrRegisterActivity.class);
                startActivity(intent);
            }

        }else {
            startActivity(new Intent(this,VideoPageActivity.class));
        }

        finish();
    }
}
